<?php
    class admin_addProductSettings_controller extends controllerBase
    {
        public function process()
        {
            $aErrors = array();
            $bIsUpdate = false;
            // Update User default add product setting
            if(isset($_POST['tb_user_title']))
            {
                if($_POST['tb_user_title'] != '')
                {
                    $bIsUpdate = true;
                    $result = database::setSetting('default_user_add_product',$_POST['tb_user_title'],$_POST['tb_user'],'add_product');
                    if(!$result)
                    {
                        $aErrors[] = 'Update Default User Add Product Fail!';
                    }
                }
                else
                {
                    $aErrors[] = 'Update Default User Add Product Fail!';
                }
            }
            // Update Menufacturer default add product setting
            if(isset($_POST['tb_menufacturer_title']))
            {
                if($_POST['tb_menufacturer_title'] != '')
                {
                    $bIsUpdate = true;
                    $result = database::setSetting('default_menufacturer_add_product',$_POST['tb_menufacturer_title'],$_POST['tb_menufacturer'],'add_product');
                    if(!$result)
                    {
                        $aErrors[] = 'Update Default Menufacturer Add Product Fail!';
                    }
                }
                else
                {
                    $aErrors[] = 'Update Default Menufacturer Add Product Fail!';
                }
            }
            
            // Update Location default add product setting
            if(isset($_POST['tb_location_title']))
            {
                if($_POST['tb_location_title'] != '')
                {
                    $bIsUpdate = true;
                    $result = database::setSetting('default_location_add_product',$_POST['tb_location_title'],$_POST['tb_location'],'add_product');
                    if(!$result)
                    {
                        $aErrors[] = 'Update Default Location Add Product Fail!';
                    }
                }
                else
                {
                    $aErrors[] = 'Update Default Location Add Product Fail!';
                }
            }
            
            // Update Category default add product setting
            if(isset($_POST['category_uri_title']))
            {
                if($_POST['category_uri_title'] != '')
                {
                    $bIsUpdate = true;
                    $result = database::setSetting('default_category_add_product',$_POST['category_uri_title'],$_POST['category_uri'],'add_product',$_POST['list_categories']);
                    if(!$result)
                    {
                        $aErrors[] = 'Update Default Category Add Product Fail!';
                    }
                }
                else
                {
                   $aErrors[] = 'Update Default Category Add Product Fail!';
                }
            }
            
            // Update number image download default add product setting
            if(isset($_POST['tb_number_image']))
            {
                if($_POST['tb_number_image'] != '')
                {
                    $bIsUpdate = true;
                    $result = database::setSetting('default_number_image_download',$_POST['tb_number_image'],'','add_product');
                    if(!$result)
                    {
                        $aErrors[] = 'Update Default Number Image Download Add Product Fail!';
                    }
                }
                else
                {
                   $aErrors[] = 'Update Default Number Image Download Add Product Fail!';
                }
            }
            
            // Update status add product setting
            if(isset($_POST['tb_status_add_product']))
            {
                if($_POST['tb_status_add_product'] != '')
                {
                    $bIsUpdate = true;
                    $result = database::setSetting('default_status_add_product',$_POST['tb_status_add_product'],'','add_product');
                    if(!$result)
                    {
                        $aErrors[] = 'Update Default Status Add Product Fail!';
                    }
                }
                else
                {
                   $aErrors[] = 'Update Default Status Add Product Fail!';
                }
            }

            if(count($aErrors) > 0)
            {
                $this->aParams['aErrors'] = $aErrors;
            }
            $this->aParams['bIsUpdate'] = $bIsUpdate;
            $aSettings = database::getListSettings('add_product');
            $this->aParams['aSettings'] = $aSettings;
        }
    }
?>
